<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	
	<style type="text/css">
	    .errorText
	    {
	        color:red;
	    }
    </style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<form id="form1" method="post">
		<input name="id" class="mini-hidden"></input>
        <div style="padding-left:40px;padding-bottom:15px;padding-top: 25px;">
            <table style="table-layout:fixed;" cellspacing="0" cellpadding="10">
            	<tr>
            		<td style="width:80px;">编号：</td>
                    <td>    
                        <input name="serialNum" onblur="judgeSerialNum();" errorMode="none" onvalidation="onserialNumValidation"  requiredErrorText="请输入编号" vtype="maxLength:15" class="mini-textbox" required="true" style="width: 180px" />
                    	<input name="serialNumHidden" class="mini-hidden" />
                    </td>
                    <td id="serialNum_error" class="errorText" ></td>
                </tr>
            	<tr>
                    <td>标题：</td>
                    <td>    
                        <input name="title" rrorMode="none" onvalidation="checkValidation" required="true" requiredErrorText="请输入标题" vtype="maxLength:255" class="mini-textbox" style="width: 180px"/>
                    </td>
                    <td id="title_error" class="errorText" ></td>
            	</tr>
            	<tr>
            		<td>调出仓库</td>
                    <td>
                        <input name="recallWhId" name="recallWhId" errorMode="none" onvalidation="checkValidation"  requiredErrorText="请选择仓库" class="mini-combobox" required="true" onitemclick="validWh();" valueField="id" style="width: 180px;" textField="name" url="allocation_find_warehouse.do" />
                    </td>
                   	<td id="recallWhId_error" class="errorText" ></td>
                </tr>
            	<tr>
            		<td>调入仓库</td>
                    <td>
                        <input name="callinWhId" errorMode="none" onvalidation="checkValidation"  requiredErrorText="请选择仓库" class="mini-combobox" required="true" onitemclick="validWh();" valueField="id" style="width: 180px;" textField="name" url="allocation_find_warehouse.do" />
                    </td>
                    <td id="callinWhId_error" class="errorText" ></td>
            	</tr>
                <tr>
                    <td>调拨时间：</td>
                    <td>
                   		<input name="allocationTime" errorMode="none" onvalidation="checkValidation"  requiredErrorText="请选择日期" class="mini-datepicker" required="true" style="width: 180px" emptyText="请选择日期"/>
                	</td>
                	<td id="allocationTime_error" class="errorText" ></td>
                </tr>
            </table>
        </div>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>

<script type="text/javascript">
	mini.parse();
	
	var form = new mini.Form("form1");
	
	//调入调出仓库验证
	function validWh(){
		var recallWhId = mini.getbyName("recallWhId").getValue();
		var callinWhId = mini.getbyName("callinWhId").getValue();
		if(recallWhId == callinWhId){
			mini.alert("同一仓库不能进行调拨！");
			return false;
		}else {
			return true;
		}
	}
	
	//保存数据
	function SaveData() {
	    var o = form.getData(true); 
	    form.validate();
	    if (form.isValid() == false || validWh() == false) return;
	    $.ajax({
	        url: "allocation_save_edit.do",
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.showTips({content:text.message,state:'danger',x:'center',y:'top'});
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
	    });
	}

	//判断编号是否重复
    function judgeSerialNum(){
    	var serialNum = mini.getbyName('serialNum').getValue();
    	var serialNumHidden = mini.getbyName('serialNumHidden').getValue();
    	var flag = true;
    	if(serialNum.length > 0 && serialNum != serialNumHidden){
	  	    $.ajax({
	  	    	url: "allocation_ver_serialnum.do?serialNum=" + serialNum,
	  	    	dataType: 'json',
	  	        cache: false,
		    	async: false,
	 	        success: function (text) {
	 	            if(text.result){
	 	            	flag = true;
	 	            }else{
	 	            	mini.alert("编码重复请修改");
	 	            	flag = false;
	 	            }
	 	        }
	  	    });
    	}
  	    return flag;
    }

	
    //标准方法接口定义
    function SetData(data) {
        if (data.action == "edit") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            form.setData(data.row);
            form.setChanged(false);
            mini.getbyName("serialNumHidden").setValue(data.row.serialNum);
        }
    }

    function GetData() {
        var o = form.getData();
        return o;
    }
    
    function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
    
    function onOk(e) {
        SaveData();
    }
    
    function onCancel(e) {
        CloseWindow("cancel");
    }
	
    function onserialNumValidation(e) {
    	 var id =e.sender.name + "_error";
         var el = document.getElementById(id);
         checkValidation(e);
        if (e.isValid) {
            if (isEnglishAndNumber(e.value) == false) {
                e.errorText = "必须输入英文+数字";
                el.innerHTML =e.errorText;
                e.isValid = false;
            }
        }
    }
    
    function isEnglishAndNumber(v) {
        var re = new RegExp("^[0-9a-zA-Z\_]+$");
        if (re.test(v)) return true;
        return false;
    }
    
    function updateError(e) {
        var id =e.sender.name + "_error";
        var el = document.getElementById(id);
        if (el) {
            el.innerHTML =e.errorText;
        }
    }
    
    function checkValidation(e) {                  
        updateError(e);
    }
</script>
</body>
</html>